<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission" />
    <div class="head-container"></div>
    <el-dialog
      v-dialog-drag
      style="width: 80vm"
      title="搜索"
      close-on-click-modal
      :visible.sync="crud.props.searchToggle"
      width="70%">
      <el-form size="small" label-width="70px">
        <el-row class="flex flex-wrap">
          <el-col :xs="24" :sm="12" :md="8" :lg="12" :xl="6">
            <el-form-item label="业务日期">
              <div class="flex flex-row">
                <el-date-picker
                  v-model="query.startDate"
                  align="right"
                  unlink-panels
                  style="width: 50%"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  range-separator=""
                  placeholder="开始日期"
                />
                <el-date-picker
                  v-model="query.endDate"
                  align="right"
                  unlink-panels
                  style="width: 50%"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  range-separator=""
                  placeholder="结束日期"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="商品品牌">
              <table-select 
                :tableColumns="[
                  { prop: 'code', label: '品牌编码', width: '100' },
                  { prop: 'name', label: '品牌名称', width: '280' },
                ]"
                :value.sync="query.goodsBrandIds"
                placeholder="请选择品牌"
                url="/api/dropDown/basGoodsBrandList"
              ></table-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="flex fow-reverse">
          <el-button
            class="filter-item"
            size="mini"
            type="primary"
            @click="queryReport"
            >搜索</el-button
          >
          <el-button
            class="filter-item"
            plain
            size="mini"
            type="primary"
            @click="resetQuery"
            style="margin-right:5px"
            >重置</el-button
          >
        </el-row>
      </el-form>
    </el-dialog>

    <!--表格渲染-->
    <el-table
      ref="table"
      border
      stripe
      :data="crud.data"
      size="small"
      style="width: 100%"
      height="700"
      @header-dragend="changeColWidth"
      :summary-method="crud.sumRow"
      @row-click="crud.selectRow"
      :row-style="crud.rowClass"
      :row-class-name="crud.tableRowClassName"
      @contextmenu.native="showMenu"
      @selection-change="crud.selectionChangeHandler">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" width="55" label="序号" />
      <el-table-column label="商品品牌" prop="goodsBrandName"></el-table-column>
      <el-table-column
        label="订单数量"
        prop="orderGoodsCount"
      ></el-table-column>
      <el-table-column label="订单箱数" prop="orderBoxCount"></el-table-column>
      <el-table-column label="订单金额" prop="orderTaxAmount"></el-table-column>
      <el-table-column label="发货数量" prop="sendGoodsCount"></el-table-column>
      <el-table-column label="发货箱数" prop="sendBoxCount"></el-table-column>
      <el-table-column label="发货金额" prop="sendTaxAmount"></el-table-column>
      <el-table-column
        label="退货数量"
        prop="returnGoodsCount"
      ></el-table-column>
      <el-table-column label="退货箱数" prop="returnBoxCount"></el-table-column>
      <el-table-column
        label="退货金额"
        prop="returnTaxAmount"
      ></el-table-column>
      <el-table-column label="销售数量" prop="saleGoodsCount"></el-table-column>
      <el-table-column label="销售箱数" prop="saleBoxCount"></el-table-column>
      <el-table-column label="销售金额" prop="saleTaxAmount"></el-table-column>
      <el-table-column label="成本金额" prop="costTaxAmount"></el-table-column>
      <el-table-column label="销售毛利" prop="saleProfit"></el-table-column>
      <el-table-column label="销售毛利率" prop="saleProfitRates"></el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from "@crud/crud";
import rrOperation from "@crud/RR.operation";
import crudOperation from "@crud/CRUD.operation";
import udOperation from "@crud/UD.operation";
import pagination from "@crud/Pagination";
import Treeselect from "@riophae/vue-treeselect";
import { publicListKey } from "@/utils/key";
import { tablemixins } from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
// crud交由presenter持有
const defaultCrud = CRUD({
  title: "品牌销售分析表",
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: false,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false,
  },
  query: {
    startDate: "",
    endDate: "",
    goodsBrandIds: "",
  },
  queryOnPresenterCreated:false,
  url: "/api/reportBrandSalesAnalysis",
  sort: "id,desc",
});
const defaultForm = {};
export default {
  name: "ReportBrandSalesAnalysis",
  components: {
    pagination,
    crudOperation,
    rrOperation,
    udOperation,
    Treeselect,
    jTableColumnConfig,
  },
  mixins: [
    presenter(defaultCrud),
    header(),
    form(defaultForm),
    crud(),
    publicListKey,
    tablemixins,
  ],
  mounted() {
    this.crud.props.searchToggle = false;
  },
  created() {
    
  },
  data() {
    return {
      costTaxAmount: " ",
      goodsBrandCode: " ",
      goodsBrandIds: [],
      goodsBrandName: " ",
      orderBoxCount: 0,
      orderGoodsCount: 0,
      orderTaxAmount: 0,
      returnBoxCount: 0,
      returnGoodsCount: 0,
      returnTaxAmount: 0,
      saleBoxCount: 0,
      saleGoodsCount: 0,
      saleProfit: 0,
      saleProfitRates: 0,
      saleTaxAmount: 0,
      sendBoxCount: 0,
      sendGoodsCount: 0,
      sendTaxAmount: 0,
      permission: {
        add: ["admin", "reportBrandSalesAnalysis:add"],
        edit: ["admin", "reportBrandSalesAnalysis:edit"],
        del: ["admin", "reportBrandSalesAnalysis:del"],
        import: ["admin", "reportBrandSalesAnalysis:import"],
        export: ["admin", "reportBrandSalesAnalysis:export"],
        copy: ["admin", "reportBrandSalesAnalysis:copy"],
        upload: ["admin", "reportBrandSalesAnalysis:upload"],
        download: ["admin", "reportBrandSalesAnalysis:download"],
      },
      rules: {},
    };
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {},
    resetQuery() {
     
      this.goodsBrandIds = [];
      this.crud.resetQuery();
    },
    queryReport() {
      this.crud.toQuery();
      this.crud.props.searchToggle = false;
    },
    
  },
};
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
.flex {
  display: flex;
}
.fow-reverse {
  flex-direction: row-reverse;
}
::v-deep .el-table--border th.el-table__cell {
  border-bottom: 1px solid #000;
}
.flex-wrap{
    flex-wrap: wrap;
}
</style>
